-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Enable signature verification in background task #10946
Enable signature verification in background task #10946
Conversation
@bkchr Can someone from parity give me feedback on this PR please? We still want to integrate signature verification as a background task :) |
@bkchr can we get a review/feedback on this please ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry sorry for all the delay.
In general it looks okay. I added some comments to improve the implementation. In general I think that frame-executive
could be less code copying when you make the "important" functions a little bit more generic. I think you will be able to manage this :)
We will also need some tests that ensure everything is working. Maybe the already existing tests are enough in frame-executive and we just need to add some step to the CI to enable the feature and run the frame-executive tests.
You should be able to copy this job here:
Lines 371 to 387 in 1f4cd99
test-frame-examples-compile-to-wasm: | |
# into one job | |
stage: test | |
<<: *docker-env | |
<<: *test-refs | |
variables: | |
<<: *default-vars | |
# Enable debug assertions since we are running optimized builds for testing | |
# but still want to have debug assertions. | |
RUSTFLAGS: "-Cdebug-assertions=y" | |
RUST_BACKTRACE: 1 | |
script: | |
- cd ./frame/examples/offchain-worker/ | |
- cargo +nightly build --target=wasm32-unknown-unknown --no-default-features | |
- cd ../basic | |
- cargo +nightly build --target=wasm32-unknown-unknown --no-default-features | |
- sccache -s |
And make it work for that :)
/// Check self in a background tas, given an instance of Context. | ||
fn background_check( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Check self in a background tas, given an instance of Context. | |
fn background_check( | |
/// Check `self` using the given `context`. | |
/// | |
/// Any signature will be checked using [`BackgroundVerify`]. | |
/// | |
/// # Security | |
/// | |
/// It is required that this is called in a [`SignatureBatching`](crate::SignatureBatching) context. | |
fn batch_verification_check( |
primitives/runtime/src/traits.rs
Outdated
/// Register a signature for background verification. | ||
/// | ||
/// This requires that background verification is enabled by doing XYZ. | ||
/// | ||
/// Returns `true` when the signature was successfully registered for background verification | ||
/// or if background verification is not enabled the signature could be verified successfully | ||
/// immediately. | ||
/// | ||
/// # Warning | ||
/// | ||
/// This requires that the background verification is finished by calling finalize_verify to | ||
/// check the result of all submitted signature verifications. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Register a signature for background verification. | |
/// | |
/// This requires that background verification is enabled by doing XYZ. | |
/// | |
/// Returns `true` when the signature was successfully registered for background verification | |
/// or if background verification is not enabled the signature could be verified successfully | |
/// immediately. | |
/// | |
/// # Warning | |
/// | |
/// This requires that the background verification is finished by calling finalize_verify to | |
/// check the result of all submitted signature verifications. | |
/// Register a signature for background verification. | |
/// | |
/// Returns `true` when the signature was successfully registered for background verification | |
/// or if background verification is not enabled the signature could be verified successfully | |
/// immediately. | |
/// | |
/// # Security | |
/// | |
/// It is required that this is called in a [`SignatureBatching`](crate::SignatureBatching) context. |
The SignatureBatching
should then be renamed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it would be valuable testing, but this does seem like something that we can test with follow-chain
command. See: https://paritytech.github.io/substrate/master/try_runtime_cli/enum.Command.html#variant.FollowChain
What you would need to do is create a polkadot binary that contains this PR and is otherwise the same as whatever is the live network, then you can run this command and let it run the real polkadot blocks inside a test env that contains batch signature verification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks much better!
Could you please check again the tests in executive that we test different kind of blocks. Meaning we want to have blocks with invalid signatures etc and then it should fail to be executed etc.
@bkchr what new name do you suggest ? |
IDK. Maybe |
@bkchr This PR is ready for a final review :) @kianenigma I ran try-runtime follow-chain on a polkadot fork that include this PR, and it seems to work well:
|
@bkchr This PR is ready and the CI is green, can you do a final review ? |
It stops working for larger blocks, when i try the With 100 extrinsics per block it works fine: # On branch PureStake:elois-background-sig-verif
cargo r --release --bin substrate --features background-signature-verification -- benchmark extrinsic --pallet system --extrinsic remark --dev --max-ext-per-block 100
Running 10 warmups...
Executing block 100 times
Building block, this takes some time...
Extrinsics per block: 100
Running 10 warmups...
Executing block 100 times
Executing a system::remark extrinsic takes[ns]:
Total: 5699353
Min: 55747, Max: 58498
Average: 56993, Median: 56988, Stddev: 402.85
Percentiles 99th, 95th, 75th: 57993, 57578, 57250 But with 1000 it panics:
It warns |
Thank you @ggwpez for your tests :) I ran the same commands as you and I got the same error. I admit I haven't understood everything yet, this is a part of the code I haven't written and haven't touched yet. hope that #12147 will indeed solve the problem. |
This pull request has been mentioned on Polkadot Forum. There might be relevant details there: https://forum.polkadot.network/t/background-signature-verification/132/1 |
Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions. |
Bring back signature batch verification but with the new name background verification.
Indeed, batch verification - in the cryptographic sense - is a different feature, and only exists for certain types of signatures.
Batch verification is currently only implemented for signatures of type sr25519. For the other types of signatures (ed25519 and ecdsa), each signature is verified alone but in a background task.
Some questions about the design:
Added an optimization suggested by @crystalin: in case the first extrinsics are particularly long to run, the background tasks that check the signatures will do nothing for a while, which is suboptimal.
It is more optimal to spawn all the signatures to be checked in the background before starting to run the extrinsics.
Closes paritytech/polkadot-sdk#351